<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="javax.sql.*, java.sql.*, com.att.network.acronym.Util" %>
<%@include file="init.jsp" %>
<%
    int ret = 0;;
    Connection con = null;
    PreparedStatement st = null;
    String name = request.getParameter("name");
    String text = request.getParameter("text");
    if (name != null && !name.isEmpty() && text != null && !text.isEmpty()) {
        name = name.toUpperCase();
        try {
            con = Util.getCon(db);
            st = con.prepareStatement("INSERT INTO acronym VALUES (null, ?, current_timestamp, ?, 1)");
            st.setString(1, name.trim());
            st.setString(2, text.trim());
            ret = st.executeUpdate();

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            con.close();
        }
    }
    if (ret < 1) {
        out.println("Some error happens: Try again");
    } else {
    //response.sendRedirect("index.jsp?q=" + name);
%>

<jsp:forward page="index.jsp">
      <jsp:param name="q" value="<%= name %>"/>
</jsp:forward>

<%}%>